﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Interactivity;

namespace Tequila.AugmentedReality
{
    public class ModifyContentPresenterCanvasZIndexBehavior : Behavior<FrameworkElement>
    {
        public Binding Binding { get; set; }

        protected override void OnAttached()
        {
            base.OnAttached();

            AssociatedObject.LayoutUpdated += AssociatedObjectOnLayoutUpdated;
        }

        private void AssociatedObjectOnLayoutUpdated(object sender, EventArgs eventArgs)
        {
            AssociatedObject.FindVisualParent<ContentPresenter>().SetBinding(Canvas.ZIndexProperty, Binding);
        }
    }
}
